<template>
  <div id="regis">
    <div class="form">
      <!-- 账号密码框的外层form开始 -->
      <el-form
        :model="ruleForm"
        status-icon
        ref="pasdForm"
        class="demo-ruleForm"
      >
        <!-- 账号框 -->
        <el-form-item prop="user">
          <el-input
            type="text"
            v-model="ruleForm.username"
            autocomplete="off"
            placeholder="用户名"
          ></el-input>
        </el-form-item>

        <!-- 密码框 -->
        <el-form-item prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.password"
            autocomplete="off"
            placeholder="密码"
          ></el-input>
        </el-form-item>
      </el-form>
      <!-- 账号密码框的外层form结束 -->

      <!-- 登录按钮 -->
      <el-button type="primary" class="el-button" @click="btn()"
        >登录</el-button
      >
    </div>
  </div>
</template>

<script>
import { Login } from "../../api/user";
export default {
  name: "RegiSter",
  data() {
    return {
      activeName: "code",
      ruleForm: {
        username: "admin",
        password: "123456",
      },
      rules: {
        input2: [
          { required: true, message: "验证码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    btn() {
      let formName = null;
      if (this.activeName === "code") {
        formName = this.$refs["pasdForm"];
      }
      formName.validate((valid) => {
        if (valid) {
          this.logins();
          this.$message({
            message: "登录成功",
            type: "success",
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    logins() {
      let obj = {
        username: this.ruleForm.username,
        password: this.ruleForm.password,
      };
      Login(obj).then((res) => {
        console.log(res);
        this.$store.commit("login/setUser", res.data.data.token);
        this.$router.push("/NaviGation");
      });
    },
  },
};
</script>

<style scoped>
.el-button {
  width: 100% !important;
}

.tops {
  margin-top: 30px;
}

#regis {
  width: 100vw;
  height: 100vh;
  background: url("../../../public/开始之地.jpg") no-repeat;
}

.form{
  width:300px;
  height:100px;
  position: absolute;
  left:0;
  top:-152px;
  bottom:0;
  right:0;
  margin:auto;
}
</style>